<!doctype html>
<html>
<head>
<title>XMLHttpRequest: calling abort() during onloadstart should not fail</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
</head>
<body>
<script>
var testAsync = async_test("Aborting during onloadstart");
testAsync.step(() => {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "resources/delay.php?iteration=1&delay=1000");
    xhr.onloadstart = testAsync.step_func(() => {
        assert_equals(xhr.readyState, XMLHttpRequest.OPENED);
        xhr.abort();
    });
    xhr.onload = testAsync.step_func(() => {
        assert_unreached("The aborted send() shouldn't go ahead, and complete.");
    });
    xhr.onabort = testAsync.step_func(() => {
        testAsync.done();
    });
    xhr.send();
});

var testAsyncUpload = async_test("Aborting during upload.onloadstart");
testAsyncUpload.step(() => {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "resources/delay.php?iteration=1&delay=1000");
    xhr.upload.onloadstart = testAsyncUpload.step_func(() => {
        assert_equals(xhr.readyState, XMLHttpRequest.OPENED);
        xhr.abort();
    });
    xhr.onload = testAsyncUpload.step_func(() => {
        assert_unreached("The aborted send() shouldn't go ahead, and complete.");
    });
    xhr.onabort = testAsyncUpload.step_func(() => {
        testAsyncUpload.done();
    });
    xhr.send("Uploaded");
});

var testAsyncResend = async_test("Resending during onloadstart");
testAsyncResend.step(() => {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "resources/delay.php?iteration=1&delay=1000");
    xhr.onloadstart = testAsyncResend.step_func(() => {
        assert_equals(xhr.readyState, XMLHttpRequest.OPENED);
        xhr.open("POST", "resources/delay.php?iteration=1&delay=1000");
        xhr.send();
    });
    xhr.onload = testAsyncResend.step_func(() => {
        assert_equals(xhr.readyState, XMLHttpRequest.DONE);
        testAsyncResend.done();
    });
    xhr.send();
});
</script>
</body>
</html>
